<{include file="admin/public/header.html"}>
<div class="am-cf admin-main">
  <!-- sidebar start -->
  <{include file='admin/public/left.html'}>
  <!-- sidebar end -->

  <!-- content start -->
  <div class="admin-content">

    <div class="am-cf am-padding">
      <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg"><{$nav[0]}></strong> / <small><{$nav[1]}></small></div>
      <div class="am-alert am-alert-success am-u-end success-msg" id="success-msg">添加成功！</div>
    </div>

    <div class="am-g">
      <div class="am-u-sm-12 am-u-md-6">
        <div class="am-btn-toolbar">
          <div class="am-btn-group am-btn-group-xs">
            <button id="add-cate" type="button" class="am-btn am-btn-default"  onclick="jumpUrl('/admin/article/add')"><span class="am-icon-plus"></span> 新增</button>
            <{if $del}>
            <button id="recover-cate" type="button" class="am-btn am-btn-default"><span class="am-icon-heart"></span> 恢复</button>
            <{else}>
            <button id="recommend-cate" type="button" class="am-btn am-btn-default"><span class="am-icon-star"></span> 推荐</button>
            <button id="top-cate" type="button" class="am-btn am-btn-default"><span class="am-icon-thumbs-up"></span> 置顶</button>
            <button id="hot-cate" type="button" class="am-btn am-btn-default"><span class="am-icon-bomb"></span> 热门</button>
            <button id="examine-cate" type="button" class="am-btn am-btn-default"><span class="am-icon-archive"></span> 审核</button>
            <{/if}>
            <button id="del-cate" type="button" class="am-btn am-btn-default"><span class="am-icon-trash-o"></span> 删除</button>
          </div>
        </div>
      </div>

      <form class="am-form" id="search-content">
      <div class="am-u-sm-12 am-u-md-3">
        <div class="am-form-group">
          <select data-am-selected="{btnSize: 'sm',maxHeight: 400}" name="cate_id" id="cate_id">
            <option value="0">所有类别</option>
            <{foreach from=$cateList item="val"}>
            <option value="<{$val.id}>" <{if isset($cate_id) && $cate_id eq $val.id}> selected<{/if}>><{$val.cate}></option>
              <{foreach from=$val.child item="va"}>
              <option value="<{$va.id}>" <{if isset($cate_id) && $cate_id eq $va.id}> selected<{/if}>>&nbsp;&nbsp;└-<{$va.cate}></option>
                <{foreach from=$va.child item="v"}>
                <option value="<{$v.id}>" <{if isset($cate_id) && $cate_id eq $v.id}> selected<{/if}>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└-<{$v.cate}></option>
                <{/foreach}>
              <{/foreach}>
            <{/foreach}>
          </select>
        </div>
      </div>
      <div class="am-u-sm-12 am-u-md-3">
        <div class="am-input-group am-input-group-sm">
          <input type="text" name="title" class="am-form-field" placeholder="输入文章标题" value="<{if isset($title)}><{$title}><{/if}>">
          <span class="am-input-group-btn">
            <button class="am-btn am-btn-default" type="button" id="search">搜索</button>
          </span>
        </div>
      </div>
      </form>
    </div>

    <div class="am-g">
      <div class="am-u-sm-12">
        <form class="am-form">
          <table class="am-table am-table-striped am-table-hover table-main">
            <thead>
              <tr>
                <th class="table-check"><input type="checkbox" id="allCheck" name="check" /></th>
                <th class="table-id">ID</th><th class="table-title">标题</th>
                <th class="table-type">分类</th>
                <th class="table-type">发布人</th>
                <th class="table-type">推荐</th>
                <th class="table-type">置顶</th>
                <th class="table-type">热门</th>
                <th class="table-type">审核</th>
                <th class="table-type">排序</th>
                <th class="table-date am-hide-sm-only">修改日期</th>
                <th class="table-set">操作</th>
              </tr>
          </thead>
          <tbody>
            <{foreach from=$list item="val"}>
            <tr>
              <td><input type="checkbox" name="check" rid="<{$val.id}>" /></td>
              <td><{$val.id}></td>
              <td><a href="/admin/article/add?id=<{$val.id}>"><{$val.title}></a></td>
              <td><{$val['cate']}></td>
              <td><{$val['username']}></td>
              <td><span class="am-btn <{if $val['recommend']==1}>am-btn-success<{else}>am-btn-warning<{/if}> am-round am-btn-xs"><{$val['recommend_str']}></span></td>
              <td><span class="am-btn <{if $val['top']==1}>am-btn-success<{else}>am-btn-warning<{/if}> am-round am-btn-xs"><{$val['top_str']}></span></td>
              <td><span class="am-btn <{if $val['hot']==1}>am-btn-success<{else}>am-btn-warning<{/if}> am-round am-btn-xs"><{$val['hot_str']}></span></td>
              <td><span class="am-btn <{if $val['audit']==1}>am-btn-success<{elseif $val['audit']==0}>am-btn-secondary<{else}>am-btn-warning<{/if}> am-round am-btn-xs"><{$val['audit_str']}></span></td>
              <td><{$val['sort']}></td>
              <td class="am-hide-sm-only"><{$val.time|date_format:'%Y-%m-%d %H:%M:%S'}></td>
              <td>
                <div class="am-btn-toolbar">
                  <div class="am-btn-group am-btn-group-xs">
                    <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="jumpUrl('/admin/article/add?id=<{$val.id}>')"><span class="am-icon-pencil-square-o"></span> 编辑</button>
                    <!-- <button type="button" class="am-btn am-btn-default am-btn-xs am-hide-sm-only" onclick="copy(<{$val.id}>)"><span class="am-icon-copy"></span> 复制</button> -->
                    <button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="del(<{$val.id}>)"><span class="am-icon-trash-o"></span> 删除</button>
                  </div>
                </div>
              </td>
            </tr>
            <{/foreach}>
            
          </tbody>
        </table>
        <div class="am-cf">
          <div class="am-fr">
              <ul class="am-pagination">
              <{$page}>
              </ul>
          </div>
        </div>
          <hr />
          <p>注：.....</p>
        </form>
      </div>

    </div>
  </div>
  <!-- content end -->
</div>
<div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">温馨提示</div>
    <div class="am-modal-bd">
      你，确定要删除这篇文章吗？
    </div>
    <div class="am-modal-footer">
      <span class="am-modal-btn" data-am-modal-cancel>取消</span>
      <span class="am-modal-btn" data-am-modal-confirm>确定</span>
    </div>
  </div>
</div>

<{include file='admin/public/footer.html'}>
<script>
$('#search').on('click', function() {
    var titleobj = $('input[name="title"]');
    var title = titleobj[0].value;
    var cate_id = $('#cate_id').val();
    if (title == '' && cate_id == 0) 
    {
      alert('分类和标题至少选择一项！');
      return false;
    }
    var recycle = $.getUrlParam('recycle');
    var url = '/admin/article/index?title=' + title + '&cate_id=' + cate_id;
    if (recycle == 1) 
    {
      url += '&recycle=1'; 
    }
    jumpUrl(url);
  });


  $('#allCheck').on('click', function(){
    var check = $('input[name="check"]');
    for (var i = 0; i < check.length; i++) {  
        if(check[0].checked){  
          check[i].checked = true;
        }
        else
        {
          check[i].checked = false;
        }
    } 
  })

  $('#examine-cate').on('click', function(){
    var data = getId();
    checkPost(data, 1);
  })

  $('#recommend-cate').on('click', function(){
    var data = getId();
    checkPost(data, 2);
  })

  $('#top-cate').on('click', function(){
    var data = getId();
    checkPost(data, 3);
  })

  $('#hot-cate').on('click', function(){
    var data = getId();
    checkPost(data, 4);
  })

  $('#del-cate').on('click', function(){
    var data = getId();
    del(data);
  })

  $('#recover-cate').on('click', function(){
    var data = getId();
    var url = "/admin/article/notDelete?recover=1&id=" + data;
    post(url);
  })

  function getId()
  {
    var check = $('input[name="check"]');
    var data = '';
    for (var i = 0; i < check.length; i++) {  
        if(check[i].checked){
          if (data) {
            data += ',' + $(check[i]).attr('rid');
          }
          else
          {
            data = $(check[i]).attr('rid');
          }
        }
    } 
    return data;
  }

  function checkPost(data, type)
  {
    var url = "/admin/article/check?type=" + type + "&id=" + data;
    post(url);
  }

  function del(id)
  {
    <{if $del}>var url = "/admin/article/del?id=" + id;<{else}>var url = "/admin/article/notDelete?id=" + id;<{/if}>
    $('#my-confirm').modal({
        relatedTarget: this,
        onConfirm: function(options) {
          post(url);
        },
        // closeOnConfirm: false,
        onCancel: function() {
          
        }
      });
  }

</script>
</body>
</html>
